package me.landery.modules.sinco.domain;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import me.landery.base.BaseEntity;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;
import java.util.Objects;

/**
 * @Author cc.w
 * @Date 2022/6/15 14:43
 * @Version 1.0
 */
@Entity
@Getter
@Setter
@Table(name="sinco_news")
public class News extends BaseEntity implements Serializable {
    @Id
    @Column(name = "news_id", nullable = false)
    @NotNull(groups = BaseEntity.Update.class)
    @ApiModelProperty(value = "新闻ID", hidden = true)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @NotBlank
    @ApiModelProperty(value = "新闻标题")
    private String title;

    @NotBlank
    @ApiModelProperty(value = "新闻内容")
    private String content;

    @ApiModelProperty(value = "发布时间")
    private Date time;

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        News mode = (News) o;
        return Objects.equals(id, mode.id) &&
                Objects.equals(title, mode.title);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, title);
    }

    public void copy(News source){
        BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
    }
}
